import requests
import pandas as pd
import os

def get_all_expert_ids():
    url = "https://i.cmzj.net/bbx/getBbxSchemeListByPC"
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
    }
    expert_ids = set()

    form_data = {"limit": "50", "page": "1", "lottery": "4", "issue": "25077", "type": "1", "follow": "0", "payState": "1"}
    response = requests.post(url, data=form_data, headers=headers, timeout=10)
    data = response.json()

    if data["code"] != 0 or not data.get("data"):
        return list(expert_ids)

    for item in data["data"][0]["pageData"]:
        expert_ids.add(item["expertId"])

    return list(expert_ids)

def main():
    if not os.path.exists("csv"):
        os.makedirs("csv")
    ids = get_all_expert_ids()
    df = pd.DataFrame({
        '序号': range(1, len(ids) + 1),
        'id': ids
    })
    df.to_csv("./csv/ids.csv", index=False)

if __name__ == "__main__":
    main()